package util2;

import java.util.concurrent.Semaphore;

public class SemaphoreUtil2 {
	public static void main(String[] args) {
		Semaphore semaphore = new Semaphore(1);
		for (int i = 0; i < 10; i++) {
			new Thread(()->{
				try {
					semaphore.acquire();
					for (int j = 0; j < 10; j++) {
						Thread.sleep(1000);
						System.out.println(Thread.currentThread().getName()+":" + j);
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				semaphore.release();
			}).start();
		}
	}
}
